Sunlight is shown coming in from the right. The earth, of course, is at the center of the diagram. The moon is shown at 8 key stages during its revolution around the earth. The dotted line from the earth to the moon represents your line of sight when looking at the moon. To help you visualize how the moon would appear at that point in the cycle, you can look at the larger moon image. The moon phase name is shown alongside the image.
One important thing to notice is that exactly one half of the moon is always illuminated by the sun. Of course that is perfectly logical, but you need to visualize it in order to understand the phases. At certain times we see both the sunlit portion and the shadowed portion -- and that creates the various moon phase shapes we are all familiar with. Also note that the shadowed part of the moon is invisible to the naked eye; in the diagram above, it is only shown for clarification purposes.
So the basic explanation is that the lunar phases are created by changing angles (relative positions) of the earth, the moon and the sun, as the moon orbits the earth.